 /**
 * @desc 界面-交互反馈
 */
const feedback = {

  showToast(title) {
    wx.showToast({
      title: title,
      icon: '',
      image: '',
      duration: 1500,
      mask: true,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) {
      },
    })
  },

  showLoading(title, mask = true) {
    wx.showLoading({
      title: title,
      mask: mask,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  hideToast() {
    wx.hideToast();
  },

  hideLoading() {
    wx.hideLoading();
  },
  
  // data = {
  //   title: '提示',
  //   content: '温馨提示',
  //   showCancel: true,
  //   cancelText: '取消',
  //   cancelColor: '#000000',
  //   confirmText: '确定',
  //   confirmColor: '#3CC51F',
  // },

  showModal(data) {
    return new Promise((resolve, reject) => {
      
      data = Object.assign({
        title: '提示',
        content: '温馨提示',
        showCancel: true,
        cancelText: '取消',
        cancelColor: '#000000',
        confirmText: '确定',
        confirmColor: '#3CC51F',
        success: function (res) {
          if (res.confirm) resolve(res);
          if (res.cancel) reject();
        },
        fail: function (res) { reject() },
        complete: function (res) { },
      }, data )  

      wx.showModal(data)
    })
  },

  showActionSheet(itemList, color) {
    return new Promise((resolve, reject) => {
      wx.showActionSheet({
        itemList: itemList,
        itemColor: color ? color :'#000000',
        success: function (res) { resolve(res.tapIndex) },
        fail: function (res) { reject() },
        complete: function (res) { },
      })
    })
  }

}

module.exports = feedback